import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/member.dart';
import '../widgets/member_list.dart';
import '../widgets/add_member_dialog.dart';
import '../providers/auth_provider.dart';
import '../widgets/custom_window_frame.dart';

class MemberScreen extends StatelessWidget {
  const MemberScreen({super.key});

  @override
  Widget build(BuildContext context) {
    // 检查权限
    final bool isAdmin = context.watch<AuthProvider>().isAdmin;
    if (!isAdmin) {
      // 如果不是管理员，显示无权限提示并返回
      WidgetsBinding.instance.addPostFrameCallback((_) {
        Navigator.of(context).pop();
        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(content: Text('您没有权限访问此页面')),
        );
      });
      return const SizedBox.shrink();
    }

    return CustomWindowFrame(
      title: '成员管理',
      child: Scaffold(
        appBar: AppBar(
          title: const Text('团队成员'),
          backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        ),
        body: const MemberList(),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            _showAddMemberDialog(context);
          },
          child: const Icon(Icons.person_add),
        ),
      ),
    );
  }

  void _showAddMemberDialog(BuildContext context) {
    showDialog(
      context: context,
      builder: (context) => const AddMemberDialog(),
    );
  }
} 